#include "myFunctions.h"
#include "bpNet.h"

int main(int argc,char *argv[]){
	bpNet Network;
	int neurons[] = {2,4,1};

	float **vRand;	
	float **targets;

	int numPatterns = 1000;
	int maxEpocas = 5000;
    double deltaError = 0.1;
  
	vRand = (float**)calloc(numPatterns,sizeof(float *));
	targets = (float **)calloc(numPatterns,sizeof(float*));
	for (int i=0; i<numPatterns ; i++){
		vRand[i] = (float *)calloc(2,sizeof(float));  //10000x2                       
		targets[i] = (float *)calloc(1,sizeof(float));  //10000x1
	}     

	// los patrones abarcan un rango de [-0.9,0.9], cosa de cubrir aprox la misma superficie ambas clases
	for (int i=0;i<numPatterns;i++){
		vRand[i][0] = normRandom() * 1.8 - 0.9;
		vRand[i][1] = normRandom() * 1.8 - 0.9;		
		if (sqrt(vRand[i][0]*vRand[i][0] + vRand[i][1]*vRand[i][1]) >= sqrt(2)/2 )
			targets[i][0] = 1.0;
		else
			targets[i][0] = -1.0; 
	}
	Network.init(neurons,3);
	Network.RandomWeights();  

	if (Network.BpTrain(vRand,targets,numPatterns,maxEpocas,deltaError)){
		cout<<"Entreno"<<endl;
		Network.Save("circulo.txt");
	}
	
	else 
		cout<<"Falta entrenar"<< endl; 
	
	return 1;
}
